package com.czxy.service;

import com.czxy.client.UserClient;
import com.czxy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Liuyunqin 17674029449@163.com
 * @date 2018/12/17 17:31
 */
@Service
@Transactional
public class AuthService {

    @Autowired
    private UserClient userClient;

    /**
     * 根据用户电话号码和密码查询用户
     * @param user
     * @return
     */
    public User findUserByMobile(User user){
        //1. 发送请求，访问web-Service
        ResponseEntity<User> userByMobile = this.userClient.findUserByMobile(user.getMobile(), user.getPassword());
        //2. 判断是否有数据,如果没有数据
        if (!userByMobile.hasBody()) {
            return null;
        }
        //3. 返回数据User
        User body = userByMobile.getBody();
        return body;
    }
}
